package days48;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class day48 {
    public int findMaxGap(int[] A, int n) {
        Arrays.sort(A);
        return A[n-1]-A[0];
    }
    public static int[] clockwisePrint(int[][] mat, int n, int m) {
        int b = n-1;
        int a = m-1;
        int c = 0;
        int d = 0;
        List<Integer> list = new ArrayList<>();
        if (a==c) {
            for (int i = 0; i < mat.length; i++) {
                list.add(mat[i][0]);
            }
        }else if(b==d){
            for (int i = 0; i < mat[0].length; i++) {
                list.add(mat[0][i]);
            }
        }else {
            while (c <= a && d <= b) {
                for (int i = c; i <= a; i++) {
                    list.add(mat[d][i]);
                }
                for (int i = d + 1; i < b; i++) {
                    list.add(mat[i][a]);
                }
                for (int i = a; i > c; i--) {
                    list.add(mat[b][i]);
                }
                for (int i = b; i > d; i--) {
                    list.add(mat[i][c]);
                }
                c++;
                a--;
                d++;
                b--;
            }
        }
        int[] arr =new int[mat.length*mat[0].length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }
    public static void main10(String[] args) {
//        int [][] arr= {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
//        int [][] arr= {{1,2,3},{4,5,6},{7,8,9}};

//        int[][] arr={{57,50,59,18,31,13},{67,86,93,86,4,9},{38,98,83,56,82,90},{66,50,67,11,7,69},{20,58,55,24,66,10},{43,26,65,0,64,28},{62,86,38,19,37,98}};
        int [][]arr={{98,30,17},{38,96,90},{17,0,50},{44,12,67},{12,79,43},{43,63,40},{19,93,48}};
       System.out.println(clockwisePrint(arr, 7, 3));
    }

    int k1=1;
    int k2=0;
    static ThreadLocal<String> threadLocal =new ThreadLocal<String>();
    public static void main(String[] args) {
        Thread thread1 =new Thread(()->{
            while (true) {
                if (threadLocal.get() == null){
                    threadLocal.set(Thread.currentThread().getName()+System.currentTimeMillis());
                }else {
                    System.out.println(threadLocal.get());
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread1.start();

        Thread thread2 = new Thread(()->{
            while (true) {
                if (threadLocal.get() == null){
                    threadLocal.set(Thread.currentThread().getName()+System.currentTimeMillis());
                }else {
                    System.out.println(threadLocal.get()+"123");
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread2.start();
    }
}
